﻿namespace CSharpPro._1020;

using System;

class demo1
{
    public static void Test1()
    {
        int[] array = { 64, 34, 25, 12, 22, 11, 90 };
        BubbleSort(array);
        foreach (int num in array)
        {
            Console.Write(num + " ");
        }
    }

    static void BubbleSort(int[] arr)
    {
        int n = arr.Length;
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = 0; j < n - i - 1; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    // 交换arr[j]和arr[j + 1]
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}